package top.quercus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.quercus.pojo.User;
import top.quercus.service.RegisterService;
import top.quercus.utils.AjaxResult;
import top.quercus.utils.StringUtils;

import static top.quercus.utils.AjaxResult.error;
import static top.quercus.utils.AjaxResult.success;


@Controller
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    @GetMapping("/register")
    public String register() {
        return "register";
    }

    @GetMapping("/readme")
    public String readme() {
        return "readme";
    }

    @PostMapping("/register")
    @ResponseBody
    public AjaxResult ajaxRegister(User user) {
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

}
